class Solution(object):
    def groupAnagrams(self, strs):
        """
        :type strs: List[str]
        :rtype: List[List[str]]
        """
        strs = list(map(lambda s : (sorted(s), s), strs))
        strs.sort(key=lambda s:s[0])
        groups = []
        group = []
        last = None
        for s in strs:
            if s[0]!=last:
                groups.append(group)
                group = []
            group.append(s[1])
            last = s[0]
        groups.append(group)
        groups.pop(0)
        return groups

print(Solution().groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))